<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('投资者适当性') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('出资人')" prop="userName">
        <el-input
          v-model="queryParams.userName"
          :placeholder="$t('出资人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('出资人类型')" prop="type">
        <el-select v-model="queryParams.type" :placeholder="$t('出资人类型')" clearable>
          <el-option
            v-for="dict in customerTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('合伙人类型')" prop="partnerType">
        <el-select
          v-model="queryParams.partnerType"
          :placeholder="$t('合伙人类型')"
          clearable
        >
          <el-option
            v-for="dict in partnerTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:appropriate:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['fund:appropriate:export']"-->
      <!--          type="warning"-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="exportHandle"-->
      <!--        >{{ $t('导出') }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="fundInvestorAppropriateList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('出资人类型')" align="center" prop="type" :formatter="customerTypeFormat" />
      <el-table-column :label="$t('出资人名称')" align="center" prop="userName">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.userName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('合伙人类型')" align="center" prop="partnerType" :formatter="partnerTypeFormat" />
      <el-table-column :label="$t('投资者性质')" align="center" prop="investorNature" :formatter="investorNatureFormat" />
      <el-table-column :label="$t('投资者专业性')" align="center" prop="investorMajor" :formatter="investorMajorFormat" />
      <!--      <el-table-column :label="$t('资料是否上传完成')" align="center" prop="checkFile">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span :style="scope.row.checkFile === 'Y'?'color:#67c23a':'color:#f56c6c'">{{ checkFileFormat(scope.row) }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fund:appropriate:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['fund:appropriate:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投资者适当性对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundInvestorAppropriateForm ref="fundInvestorAppropriateForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listFundInvestorAppropriate, delFundInvestorAppropriate } from '@/api/fund/appropriate/fundInvestorAppropriate'
import fundInvestorAppropriateForm from './fundInvestorAppropriateForm.vue'
export default {
    components: {
        fundInvestorAppropriateForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 投资者适当性表格数据
          fundInvestorAppropriateList: [],
          // 弹出层标题
          title: '投资者适当性',
          // 是否显示弹出层
          formOpen: false,
        // 出资人类型字典
        customerTypeOptions: [],
        // 合伙人类型字典
       partnerTypeOptions: [],
        // 投资者性质字典
        investorNatureOptions: [],
        // 投资者专业性字典
        investorMajorOptions: [],
        // 资料是否上传完成
        checkFileOptions: [],
          // 查询参数
          queryParams: {
              fundId: this.$route.query.id,
              type: undefined,
              userName: undefined,
              partnerType: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('lp_type').then(response => {
      response.data.forEach(item => {
        this.customerTypeOptions.push(item)
      })
      this.getDicts('main_body_type').then(response => {
        response.data.forEach(item => {
          this.customerTypeOptions.push(item)
        })
      })
    })
      this.getDicts('partner_type').then(response => {
          this.partnerTypeOptions = response.data
      })
      this.getDicts('investor_nature').then(response => {
          this.investorNatureOptions = response.data
      })
      this.getDicts('investor_majors').then(response => {
          this.investorMajorOptions = response.data
      })

    this.getDicts('sys_yes_no').then(response => {
      this.checkFileOptions = response.data
    })
  },
  methods: {
    /** 查询投资者适当性列表 */
    getList() {
        this.loading = true
        listFundInvestorAppropriate(this.queryParams).then(response => {
            this.fundInvestorAppropriateList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 出资人类型字典翻译
    customerTypeFormat(row) {
      return this.selectDictLabel(this.customerTypeOptions, row.type)
    },
    // 合伙人类型字典翻译
    partnerTypeFormat(row) {
      return this.selectDictLabel(this.partnerTypeOptions, row.partnerType)
    },
    // 投资者性质字典翻译
    investorNatureFormat(row) {
      return this.selectDictLabel(this.investorNatureOptions, row.investorNature)
    },
    // 投资者专业性字典翻译
    investorMajorFormat(row) {
      return this.selectDictLabel(this.investorMajorOptions, row.investorMajor)
    },
    // 资料是否上传完成
    checkFileFormat(row) {
      return this.selectDictLabel(this.checkFileOptions, row.checkFile)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,

            userName: undefined,

            fundId: undefined,

            type: undefined,

            customerId: undefined,

            partnerType: undefined,

            investorNature: undefined,

            investorMajor: undefined,

            riskTolerance: undefined,

            remark: undefined,

            createBy: undefined,

            createTime: undefined,

            updateBy: undefined,

            updateTime: undefined,

            delFlag: undefined

        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.fundInvestorAppropriateForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.fundInvestorAppropriateForm.init(row)
          debugger
          console.log(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delFundInvestorAppropriate(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    }
  }
}
</script>
